﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using BLL;
using Utils;

namespace UI.ModSalary
{
    public partial class ShortageList : System.Web.UI.Page
    {
        ShortageBiz shortageBiz = new ShortageBiz();
        string account = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] != null)
            {
                User user = Session["user"] as User;
                account = user.Account;
            }
            else
            {
                JSUtility.Alert(this, "您没有登录!请先登录。");
                return;
            }
            if (!IsPostBack)
            {
                new DepartmentBiz().InitDropDownList(ddlDeptID, "0");
                btnAdd.Attributes.Add("onclick", "javascript:ShowLink('ShortageAdd.aspx',800,550);");
                btnIn.Attributes.Add("onclick", "javascript:ShowLink('ShortageImport.aspx',640,480);");
                BondGvList("", "", System.DateTime.Now.AddDays(-10).ToString("yyyy-MM-dd"), System.DateTime.Now.ToString("yyyy-MM-dd"));
            }
        }
        protected void BondGvList(string deptName, string serWord, string bTime, string eTime)
        {
            DataTable dt = shortageBiz.GetLists(deptName, serWord, bTime, eTime);
            if (dt.Rows.Count > 0)
            {
                lbAmount.Text = "合计:    " + dt.Rows.Count;
            }
            else
            {
                lbAmount.Text = "";
            }
            gvList.DataSource = dt;
            gvList.DataBind();

        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "ShortageList.aspx", RightChar.Ser))
            {
                JSUtility.Alert(this, "无权限！");
                return;
            }
            string deptName = ddlDeptID.SelectedItem.Text.Trim();
            if (deptName == "请选择部门") deptName = "";
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();

            if (serWord == "" && bTime == "" && eTime == "" && deptName == "")
            {
                JSUtility.Alert(this, "至少输入一个查询条件");
                return;
            }
            if (StringUtility.GetDiffDays(bTime, eTime) > XmlUtility.GetNumFormConfig("daysOfSearch"))
            {
                JSUtility.Alert(this, "查询日期间隔不能大于" + XmlUtility.GetNumFormConfig("daysOfSearch") + "天！");
                return;
            }
            BondGvList(deptName, serWord, bTime, eTime);


        }
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "ShortageList.aspx", RightChar.Out))
            {
                JSUtility.Alert(this, "无权限！");
                return;
            }
            //ExcelUtility.GridViewToExcel(gvList, "EmpRewards.xls");
            string deptID = ddlDeptID.SelectedItem.Text.Trim();
            if (deptID == "请选择部门") deptID = "";
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();

            ExcelUtility.ExportDsToXls(this, shortageBiz.GetOutLists(deptID, serWord, bTime, eTime), "ShortageList.xls");
        }


        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F3F8F8'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            }
        }

        

    }
}